package raytracing;
import scene.shape.geometry.Primitive;
import util.Vector3f;

/**
 * Container for information regarding a ray hit
 * @author glenn
 *
 */
public class HitRecord {
	
	private boolean hasHit;
	private float t, beta, gamma;
	private Ray r;
	private Vector3f normal;
	private Primitive primitive;
	
	public static final HitRecord NOHIT = new HitRecord(false, Float.NaN, null, null, null,0f,0f);
	
	
	/**
	 * Constructs a new HitRecord
	 * @param hasHit indicates wether or not a hit has occured
	 * @param t the fractional distance along the ray where the collision has occured
	 * @param r the ray along which the collision occured
	 * @param normal the normal of the surface at the collision point, this should be normalized
	 */
	public HitRecord(boolean hasHit, float t, Ray r, Vector3f normal, Primitive p, float beta, float gamma){
		this.hasHit = hasHit;
		this.t = t;
		this.r = r;
		this.normal = normal;
		this.primitive = p;
		this.beta = beta;
		this.gamma = gamma;
	}
	
	/**
	 * Constructs a new HitRecord
	 * @param hasHit indicates wether or not a hit has occured
	 * @param t the fractional distance along the ray where the collision has occured
	 * @param r the ray along which the collision occured
	 * @param normal the normal of the surface at the collision point, this should be normalized
	 */
	public HitRecord(boolean hasHit, float t, Ray r, Vector3f normal, Primitive p){
		this.hasHit = hasHit;
		this.t = t;
		this.r = r;
		this.normal = normal;
		this.primitive = p;
	}
	
	/**
	 * Constructs a new HitRecord
	 * @param hasHit indicates wether or not a hit has occured
	 * @param t the fractional distance along the ray where the collision has occured
	 * @param r the ray along which the collision occured
	 * @param normal the normal of the surface at the collision point, this should be normalized
	 */
	public HitRecord(boolean hasHit, float t, Ray r, Vector3f normal){
		this.hasHit = hasHit;
		this.t = t;
		this.r = r;
		this.normal = normal;
	}

	/**
	 * @return An indication wether or not a hit has occured
	 */
	public boolean hasHit() {
		return hasHit;
	}

	/**
	 * @return The fractional distance along the ray where the collision has occured
	 */
	public float getT() {
		return t;
	}

	/**
	 * @return the r
	 */
	public Ray getRay() {
		return r;
	}
	
	/**
	 * @return The normal of the surface at the collision point
	 */
	public Vector3f getNormal(){
		return normal;
	}
	
	/**
	 * @return The collision point
	 */
	public Vector3f getIntersectionPoint(){
		return r.param(t);
	}
	

	public Primitive getPrimitive() {
		return primitive;
	}
	
	public float getBeta(){
		return beta;
	}
	
	public float getGamma(){
		return gamma;
	}
}
